<template>
  <div class="zc">
    <div>
      <h2>注册账号</h2>
      <span>账&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</span>
      <input type="text" placeholder="账号" v-model="user" /><br /><br />
      <span>密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：</span>
      <input type="password" placeholder="密码" v-model="password" /><br /><br />
      <span>确认密码：</span>
      <input type="password" placeholder="再出输入密码" v-model="qrpassword" />
      <button @click="yan">确认注册</button>
      <router-link
        :to="{ name: 'Loginden', params: { id: this.$route.params.id } }"
        tag="button"
        >取消</router-link
      >
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: "zc",
  data() {
    return {
      user: "",
      password: "",
      qrpassword: "",
    };
  },
  methods: {
    yan() {
      if (this.user != "" && this.password != "" && this.qrpassword != "") {
        if (this.password == this.qrpassword) {
          this.ajax({
            method: "post",
            url: "/addUser",
            data: {
              name: this.user,
              password: this.password,
            },
          }).then((res) => {
            // this.text=res.data;
            alert(res.data);
            if (res.data == "注册成功") {
              // localStorage.user = res.data;
              this.$router.push({
                name: "Loginden",
                params: { id: this.$route.params.id },
              });
            }
          });
        } else {
          alert("两次密码不一致，请重新输入");
          this.password = "";
          this.qrpassword = "";
        }
      } else {
        alert("账号密码不能为空");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.zc {
  width: 100%;
  //   text-align: center;
  padding-top: 50px;
  > div {
    margin: auto;
    text-align: center;
    width: 350px;
    border: 1px solid rgb(138, 134, 134);
    background-color: rgb(233, 233, 233);
    padding: 10px;
    > button {
      margin: 20px 19px;
      width: 100px;
      height: 40px;
      background-color: rgb(185, 185, 185);
    }
  }
}
</style>